package com.example.vulnerableapplication.provider;

import android.content.Intent;
import android.net.Uri;
import android.os.Bundle;
import android.util.Log;
import android.view.View;
import android.widget.Button;

import androidx.appcompat.app.AppCompatActivity;

import com.example.vulnerableapplication.R;

import java.io.FileNotFoundException;
import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStream;

public class grantUriPermissionsActivity extends AppCompatActivity {
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_granturipermissions);
        Button btn = findViewById(R.id.btn_grantUriPermissions);

//        btn.setOnClickListener(new View.OnClickListener() {
//            @Override
//            public void onClick(View v) {
//                //测试contentprovider
//                try {
//                    String str = "content://" + "com.example.student" +"/out";
//                    InputStream is = getContentResolver().openInputStream(Uri.parse(str));
//                    byte[] buffer = new byte[1024];
//                    int byteCount;
//                    while ((byteCount = is.read(buffer)) != -1) {
//                        Log.e("Rzx",new String(buffer));
//                    }
//                    is.close();
//
//                } catch (FileNotFoundException e) {
//                    e.printStackTrace();
//                } catch (IOException e) {
//                    e.printStackTrace();
//                }

//                Intent intent = new Intent();
//                intent.setFlags(Intent.FLAG_GRANT_READ_URI_PERMISSION |
//                        Intent.FLAG_GRANT_WRITE_URI_PERMISSION |
//                        Intent.FLAG_GRANT_PERSISTABLE_URI_PERMISSION  |
//                        Intent.FLAG_GRANT_PREFIX_URI_PERMISSION);
//                intent.setClassName("com.example.exploitapplication","com.example.exploitapplication.otherproviderActivity");
//                startActivity(intent);
//            }
//        });
        Log.e("grantUriPermissions",getIntent().toUri(Intent.URI_INTENT_SCHEME));
        setResult(-1, getIntent());
        finish();

    }
}
